package main

import (
	"context"
	"fmt"
	"gitee.com/alex_li/gpio/cmd/gpio/monitor"
	"gitee.com/alex_li/gpio/internal/etc"
	"github.com/lishimeng/app-starter"
	"github.com/lishimeng/go-log"
	"time"
)

//  GOOS=linux GOARCH=arm GOARM=7 go build -o gpio-go cmd/gpio/main.go

func main() {

	defer func() {
		if err := recover(); err != nil {
			fmt.Println(err)
		}
	}()

	err := _main()
	if err != nil {
		fmt.Println(err)
	}
	time.Sleep(time.Millisecond * 200)
}

func _main() (err error) {
	application := app.New()

	err = application.Start(func(ctx context.Context, builder *app.ApplicationBuilder) error {

		var err error
		err = builder.LoadConfig(&etc.Config, nil)
		if err != nil {
			return err
		}

		builder.
			ComponentAfter(monitor.Watch).
			PrintVersion()
		return err
	}, func(s string) {
		log.Info(s)
	})

	return
}
